package com.wswy.wzcx.ui.activity;

import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.che.libcommon.ui.BaseActivity;
import com.wswy.wzcx.R;
import com.wswy.wzcx.ui.persenter.JZCFAddPresenter;
import com.wswy.wzcx.ui.view.JZCFAddView;

/**
 * Created by wangduheng26 on 2018/3/7.
 * wangduheng26@gmail.com
 */

public class AddDriverLicenseActivity extends BaseActivity implements JZCFAddView,Toolbar.OnMenuItemClickListener {
    JZCFAddPresenter mPresenter;

    @Nullable
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mine);
        mPresenter = new JZCFAddPresenter(this,this);
        configToolBar();
        FrameLayout frameLayout = findViewById(R.id.content_frame);
        mPresenter.onCreate(frameLayout,getIntent());

    }


    @Override
    public boolean onSupportNavigateUp() {
        onBackPressed();
        return true;
    }

    public void configToolBar() {
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        Drawable drawable = ContextCompat.getDrawable(this, R.drawable.btn_close_selector);
        toolbar.setNavigationIcon(drawable);
        toolbar.setNavigationOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        findViewById(R.id.img_back).setVisibility(View.GONE);
        ((TextView)findViewById(R.id.tv_title)).setText("驾驶证查分");
        toolbar.setOnMenuItemClickListener(this);
        final ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayShowTitleEnabled(false);
            actionBar.setDisplayHomeAsUpEnabled(false);
            actionBar.setDisplayShowHomeEnabled(true);
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_add_driver_license, menu);
        return super.onCreateOptionsMenu(menu);

    }
    public static final String ACTION_QUERY_JZCF="wzcf.intent.action.query.jzcf";
    @Override
    public boolean onMenuItemClick(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.action_query:
                mPresenter.query();
                break;
        }
        return true;
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        mPresenter.onDestroy();
    }

    @Override
    public Activity activity() {
        return this;
    }
}
